package com.component.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.component.dto.CargaInicialCtrlEjecDTO;
import com.component.dto.ComponenteToRunDTO;


public class BusquedaDeComponentesDAO {
	private static Logger log = Logger.getLogger(BusquedaDeComponentesDAO.class);
	
	     public List getComponentesEjecutar(String hora, String fecha) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException{
	    		List listReporte = new ArrayList();
	    		conexionMySQL connDao = new conexionMySQL();
	    		Connection conn = connDao.getConnection();	

	    		String query = "SELECT" +
	    				" id_control_ejecucion, " +
	    				" ind_origen, " +
	    				" fecha_inicio, " +
	    				" hora_inicio," +
	    				" id_estado_parametro, " +
	    				" acp_calendario_id_calendario," +
	    				" acp_catalogo_csw_id_catalogo_csw," +
	    				" orden " +
	    				" FROM sacpro.acp_control_ejecucion" +
	    				" where fecha_inicio = curdate()" +
	    				" AND hora_inicio = 300 " +
	    				" AND  ID_ESTADO_PARAMETRO = 1";
	    		System.out.println(query);
	    		try {
	    			Statement stmt = null;
	    			stmt = conn.createStatement();
	    			ResultSet rs = stmt.executeQuery(query);
	    			while (rs.next()) {
	    				ComponenteToRunDTO componDTO = new ComponenteToRunDTO();
	    				componDTO.setIndOrigen(rs.getString(1));
	    				componDTO.setIndOrigen(rs.getString(2));
	    				componDTO.setFechaInicio(rs.getString(3));
	    				componDTO.setHoraFin(rs.getString(4));
	    				componDTO.setIdEstadoParametro(rs.getString(5));
	    				componDTO.setAcpCalendario(rs.getString(6));
	    				componDTO.setAcpCatalogo_csw(rs.getString(7));
	    				componDTO.setOrden(rs.getString(8));
	    		        listReporte.add(componDTO);	            	
	    			}
	    			rs.close();
	    			stmt.close();
	    		} catch (SQLException ex) {
	    			ex.printStackTrace();
	    			log.error("Error BusquedaDeComponentesDAO.getComponentesEjecutar SQLException: " +ex.getMessage());
	    		} finally {
	    			connDao.desconecta(conn);
	    		}
	    		return listReporte;
	     }

}
